package com.menhai.personmanagement.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.menhai.personmanagement.entity.OperationManual;
import com.menhai.personmanagement.entity.workloadStatistics;
import com.menhai.personmanagement.services.OperationManualService;
import com.menhai.personmanagement.utils.ExportSysWorkloadStatisticsInfoExcel;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/OperationManual")
public class OperationManualController {
	
	@Autowired
	private OperationManualService OperationManualService;
	
	@RequestMapping("/handleEditLook")
	public List<OperationManual> handleEditLook (OperationManual OperationManual){
		List<OperationManual> OperationManualList = new ArrayList<OperationManual>();
		OperationManualList = OperationManualService.handleEditLook(OperationManual);
        return OperationManualList;
   }
	@RequestMapping("/handleEditLooks")
	public List<OperationManual> handleEditLooks (OperationManual OperationManual){
		List<OperationManual> OperationManualList = new ArrayList<OperationManual>();
		OperationManualList = OperationManualService.handleEditLook(OperationManual);
        return OperationManualList;
   }
	
	@RequestMapping("/download")
	private void download(HttpServletRequest request, HttpServletResponse response) {
		//文件地址
		String fileUrl = request.getParameter("URL");//请求头URL等于的内容
		try {
			File file = new File("/usr/share/menghai/"+fileUrl);
//			File file = new File(ResourceUtils.getURL("classpath:").getPath()+"static/reguladion/"+fileUrl);
			// 取得文件名
	        InputStream fis = null;
            fis = new FileInputStream(file);
            request.setCharacterEncoding("UTF-8");
            fileUrl = new String(fileUrl.getBytes("UTF-8"), "ISO8859-1");
            response.reset();
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/force-download");// 设置强制下载不打开
            response.addHeader("Content-Disposition", "attachment;filename=" + fileUrl);
            response.setHeader("Content-Length", String.valueOf(file.length()));
            byte[] b = new byte[1024];
            int len;
            while ((len = fis.read(b)) != -1) {
                response.getOutputStream().write(b, 0, len);
            }
            response.flushBuffer();
            //fis.flush();
            fis.close();//强制关闭字节流
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
//	@RequestMapping("/preview")
//	private void preview(HttpServletRequest request, HttpServletResponse response) {
//		System.out.println("进入预览");
////		//文件地址
////		String fileUrl = request.getParameter("URL");//请求头URL等于的内容
////		try {
////			//File file = new File("/usr/share/menghai/"+fileUrl);
////			File file = new File(ResourceUtils.getURL("classpath:").getPath()+"static/reguladion/"+fileUrl);
////			
////		} catch (IOException e) {
////			throw new RuntimeException(e);
////		}
//		System.out.println("结束预览");
//	}
	
}
